package com.wm.blog_admin.task;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wm.blog_admin.controller.resp.TagExportResp;
import com.wm.blog_admin.query.TIconQuery;
import com.wm.blog_admin.query.TTagQuery;
import com.wm.blog_admin.service.TIconService;
import com.wm.blog_admin.service.TTagService;
import com.wm.blog_common.base.BeanUtils;
import com.wm.blog_common.bean.QueryPage;
import com.wm.blog_common.domain.TIconDO;
import com.wm.blog_common.domain.TTagDO;
import com.wm.blog_common.result.Result;
import lombok.AllArgsConstructor;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;

import java.util.Collections;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.stream.Collectors;

/**
 * @author ：半卷流年
 * @description : ${description}
 * @createTime ：2020/6/7
 */
@AllArgsConstructor
public class TagThreadTask implements Callable<List<TagExportResp>> {

    private Integer current;

    private Integer size;

    private TTagService tTagService;

    private TTagQuery tTagQuery;

    @Override
    public List<TagExportResp> call() throws Exception {
        QueryPage page = new QueryPage(current, size);
        Result<Page<TTagDO>> result = tTagService.page(page, tTagQuery);

        if(result.isSuccess() && !ObjectUtils.isEmpty(result.getData()) && !CollectionUtils.isEmpty(result.getData().getRecords())){
            return result.getData().getRecords().stream().map(item -> {
                TagExportResp resp = new TagExportResp();
                BeanUtils.copyProperties(item,resp);
                return resp;
            }).collect(Collectors.toList());
        }
        return Collections.emptyList();
    }
}
